export * from '@/hooks/useMessage'

/**
 * 解析正则表达式字符串并返回 RegExp 对象
 * @param {string} regexpString - 序列化的正则表达式字符串
 * @returns {RegExp} - 解析后的 RegExp 对象
 */
export const parseRegexp = (regexpString: string): RegExp => {
	const parts = regexpString.match(/\/(.*?)\/([gimsuy]*)/)
	if (parts) {
		return new RegExp(parts[1], parts[2])
	} else {
		throw new Error(`Invalid RegExp string format: ${regexpString}`)
	}
}

export function isExternal(str: string) {
	return /^(https?:|mailto:|tel:)/.test(str)
}

export function isCode(str: string) {
	return /^[0-9]{6}$/.test(str)
}

export function isObject(obj: any) {
	return Object.prototype.toString.call(obj) === '[object Object]'
}

export function isEmail(str: string) {
	return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(str)
}

export function isMobile(str: string) {
	if (/[+\s]/.test(str)) {
		try {
			const phone = str.split(' ')[1]
			return /^[0-9]{7,15}$/.test(phone)
		} catch {
			return false
		}
	}
	return /^[0-9]{7,15}$/.test(str)
}

export function isLength(str: string, min: number, max: number) {
	const length = str.length
	return length >= min && length <= max
}

export function hasSpace(str: string) {
	return /\s+/g.test(str)
}

export function hasSpecialChar(str: string) {
	// eslint-disable-next-line prefer-regex-literals
	return RegExp(
		"[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？\"+]"
	).test(str)
}

export function isUsername(str: string) {
	return /^[a-zA-Z0-9]{1,}$/.test(str)
}

export function isPassword(str: string) {
	return /[a-zA-Z]/.test(str) && /[0-9]/.test(str)
}

export function isInviteCode(str: string) {
	return /^[a-zA-Z0-9]{1,}$/.test(str) && str.length <= 30
}
export function isWalletAddress(str: string) {
	return /^[A-Za-z0-9_-]{10,100}$/.test(str)
}

export const RegBettingPoints = / [\+,\-]{0,1}[0-9,\.]+$/
